const express = require('express');
const router = express.Router();
const rankingController = require('../controllers/rankingController');

router.get('/', (req, res, next) => {
  const { type = 'hall', range = 'week', limit = 10, sortBy = 'dataValue' } = req.query;
  
  // 将请求转发给相应的控制器，避免参数冲突
  req.query.sortBy = sortBy;  // 排序方式参数
  req.query.period = range;   // 时间范围参数
  req.query.limit = parseInt(limit);
  
  if (type === 'hall') {
    rankingController.getHallRankings(req, res);
  } else if (type === 'host') {
    rankingController.getHostRankings(req, res);
  } else if (type === 'overall') {
    rankingController.getOverallRankings(req, res);
  } else {
    res.status(400).json({ error: '无效的排行榜类型' });
  }
});

module.exports = router;